#!/bin/sh
PRJNAME=MinorityReport
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/TrendMicro/$PRJNAME/bin"
export PATH

GLCFG=glcfg
GGCFGFILE=/etc/ggb.conf
TRAP_ON=`$GLCFG $GGCFGFILE v snmp enable_trap`
TRAP_COMMU=`$GLCFG $GGCFGFILE v snmp trap_community`
TRAP_IP=`$GLCFG $GGCFGFILE v snmp trap_ip`

TRAP_ON=`echo $TRAP_ON | tr '[A-Z]' '[a-z]'`
if [ "$TRAP_ON" != 'yes' ]; then
	exit
fi

if [ "$TRAP_COMMU" = '' -o "$TRAP_IP" = '' ]; then
	logger "Can not sent trap without community or destination IP"
	exit 1
fi

case "$1" in
	NTPFail)
		snmptrap -v 2c -m TRENDMICRO-!!ProductNameTag!!-MIB -c $TRAP_COMMU $TRAP_IP "" NTPFail
		;;
	componentUpdateFail)
		snmptrap -v 2c -m TRENDMICRO-!!ProductNameTag!!-MIB -c $TRAP_COMMU $TRAP_IP "" componentUpdateFail productName string "!!PRODUCT_NAME_TAG!!" componentName string "$2"
		;;
	nsNotifyShutdown)
		snmptrap -v 2c -m NET-SNMP-AGENT-MIB -c $TRAP_COMMU $TRAP_IP "" nsNotifyShutdown
		;;
	*)
		echo "Usage: $0 {NTPFail | componentUpdateFail | nsNotifyShutdown}"
		;;
esac

